#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.biz.pay.weixin.form;

import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by well on 15/6/3.
 */
public class WeixinNotifyResponse {

    private String return_code;

    private String return_msg;


    public String getReturn_code() {
        return return_code;
    }

    public void setReturn_code(String return_code) {
        this.return_code = return_code;
    }

    public String getReturn_msg() {
        return return_msg;
    }

    public void setReturn_msg(String return_msg) {
        this.return_msg = return_msg;
    }

    public String toXML(){
        final StringBuilder buf = new StringBuilder();
        buf.append("<xml>");
        final Object current = this;
        ReflectionUtils.doWithFields(this.getClass(), new ReflectionUtils.FieldCallback() {
            @Override
            public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
                field.setAccessible(true);
                String name = field.getName();
                Object o = field.get(current);
                if (o != null) {
                    buf.append("<").append(name).append("><![CDATA[").append(String.valueOf(o)).append("]]></").append(name).append(">");
                }
            }
        });
        buf.append("</xml>");
        return buf.toString();
    }

    public Map<String,String> toParamMap(){
        final Map<String,String> param = new HashMap<String, String>();
        final Object current = this;
        ReflectionUtils.doWithFields(this.getClass(), new ReflectionUtils.FieldCallback() {
            @Override
            public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
                field.setAccessible(true);
                String name = field.getName();
                Object o = field.get(current);
                if(o!= null){
                    param.put(name, String.valueOf(o));
                }
            }
        });
        return param;
    }

}
